import {Routers, simpleRouter, mainRouter, appRouter} from '@/router/router';
import Util from '@/libs/util';
import Cookies from 'js-cookie';
import userStore from './user';
import Vue from 'vue';

const app = {
    state: {
    	cachePage: [],
    	menuList: []
    },
    mutations: {
    	// 更新菜单，这里可以做权限判断，显示需要展示的菜单
        updateMenulist (state) {
            state.menuList = appRouter;
        },
        // 获取需要缓存的路由，只针对登录后的页面
        initCachePage(state) {
        	let caches = [];
        	let rs = [...simpleRouter, mainRouter, ...appRouter];
        	
        	function getCacheRouteName(routes) {
        		for(let item in routes) {
        			if(routes[item].meta && routes[item].meta.cache) {
        				caches.push(routes[item].name);
        			}
        			if(routes[item].children && routes[item].children.length > 0) {
        				getCacheRouteName(routes[item].children);
        			}
        		}
        	}
        	getCacheRouteName(rs);
        	
        	state.cachePage = caches;
        }
    }
};

export default app;
